home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / util / max / expflybsp / expflybsp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-31  |  6.4 KB  |  275 lines

  1. // flyexp.cpp: implementation of the flyexp class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "expflybsp.h"
  6. #include "../../../lib/Fly3D.h"
  7. #include "scene_max.h"
  8. #include "enum_scene.h"
  9. #include <windows.h>
  10. #include <direct.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14.  
  15. int lightradius=200,savelog=1,saveobj=1,maxdepth=10,
  16.     bspmode=0,planemode=2,savebsp=1,cartoonlight=0;
  17.  
  18. int tot_vert,tot_face;
  19.  
  20. BOOL controlsInit=0;
  21.  
  22. HINSTANCE hInstance;
  23.  
  24. BOOL CALLBACK OptionsProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  25. {
  26.     switch (uiMsg)
  27.     {
  28.     case WM_COMMAND:
  29.         switch(LOWORD(wParam))
  30.         {
  31.         case IDOK:
  32.             lightradius=GetDlgItemInt(hWnd,IDC_LIGHTRADIUS,0,0)*10;
  33.             maxdepth=GetDlgItemInt(hWnd,IDC_MAXDEPTH,0,0);
  34.             savelog=IsDlgButtonChecked(hWnd,IDC_SAVETXT);
  35.             saveobj=IsDlgButtonChecked(hWnd,IDC_SAVEOBJ);
  36.             savebsp=IsDlgButtonChecked(hWnd,IDC_SAVEBSP);
  37.             bspmode=IsDlgButtonChecked(hWnd,IDC_AXISALIGNED);
  38.             planemode=IsDlgButtonChecked(hWnd,IDC_FREESPACE)+2;
  39.             cartoonlight=IsDlgButtonChecked(hWnd,IDC_CARTOONLIGHT);
  40.             if (lightradius<0)
  41.                 MessageBox(hWnd,"Inavlid light radius!","Fly3D BSP Export",MB_OK);
  42.             else
  43.             if (maxdepth<1 || maxdepth>20)
  44.                 MessageBox(hWnd,"Inavlid tree depth!\nMust be from 1 to 20.","Fly3D BSP Export",MB_OK);
  45.             else
  46.                 EndDialog(hWnd,1);
  47.             break;
  48.         case IDCANCEL:
  49.             EndDialog(hWnd,0);
  50.             break;
  51.         case IDC_SAVEBSP:
  52.             if (IsDlgButtonChecked(hWnd,IDC_SAVEBSP))
  53.                 EnableWindow(GetDlgItem(hWnd,IDC_SAVETXT),1);
  54.             else EnableWindow(GetDlgItem(hWnd,IDC_SAVETXT),0);
  55.             break;
  56.         case IDC_FACEALIGNED:
  57.             bspmode=0;
  58.             EnableWindow(GetDlgItem(hWnd,IDC_MAXDEPTH),0);
  59.             EnableWindow(GetDlgItem(hWnd,IDC_MAXDEPTHSTATIC),0);
  60.             EnableWindow(GetDlgItem(hWnd,IDC_LANDSCAPE),0);
  61.             EnableWindow(GetDlgItem(hWnd,IDC_FREESPACE),0);
  62.             break;
  63.         case IDC_AXISALIGNED:
  64.             bspmode=1;
  65.             EnableWindow(GetDlgItem(hWnd,IDC_MAXDEPTH),1);
  66.             EnableWindow(GetDlgItem(hWnd,IDC_MAXDEPTHSTATIC),1);
  67.             EnableWindow(GetDlgItem(hWnd,IDC_LANDSCAPE),1);
  68.             EnableWindow(GetDlgItem(hWnd,IDC_FREESPACE),1);
  69.             break;
  70.         }
  71.         break;
  72.  
  73.     case WM_INITDIALOG:
  74.         SetDlgItemInt(hWnd,IDC_LIGHTRADIUS,lightradius/10,0);
  75.         SetDlgItemInt(hWnd,IDC_MAXDEPTH,maxdepth,0);
  76.         CheckDlgButton(hWnd,IDC_SAVETXT,savelog);
  77.         CheckDlgButton(hWnd,IDC_SAVEOBJ,saveobj);
  78.         CheckDlgButton(hWnd,IDC_SAVEBSP,savebsp);
  79.         CheckDlgButton(hWnd,IDC_CARTOONLIGHT,cartoonlight);
  80.         CheckRadioButton(hWnd,IDC_FACEALIGNED,IDC_AXISALIGNED,IDC_FACEALIGNED+bspmode);
  81.         CheckRadioButton(hWnd,IDC_LANDSCAPE,IDC_FREESPACE,IDC_LANDSCAPE+planemode-2);
  82.         EnableWindow(GetDlgItem(hWnd,IDC_MAXDEPTH),bspmode);
  83.         EnableWindow(GetDlgItem(hWnd,IDC_MAXDEPTHSTATIC),bspmode);
  84.         EnableWindow(GetDlgItem(hWnd,IDC_LANDSCAPE),bspmode);
  85.         EnableWindow(GetDlgItem(hWnd,IDC_FREESPACE),bspmode);
  86.         break;
  87.     }
  88.     return FALSE;
  89.  
  90. //////////////////////////////////////////////////////////////////////
  91. // Construction/Destruction
  92. //////////////////////////////////////////////////////////////////////
  93.  
  94. flyexp::flyexp()
  95. {
  96. }
  97.  
  98. flyexp::~flyexp()
  99. {
  100. }
  101.  
  102. #ifdef MAX3
  103. int flyexp::DoExport(const TCHAR *name, ExpInterface *ei, Interface *i, BOOL suppressPrompts, DWORD options)    // max 3.x
  104. #endif
  105. #ifdef MAX2
  106. int flyexp::DoExport(const TCHAR *name, ExpInterface *ei, Interface *i, BOOL suppressPrompts)                    // max 2.x
  107. #endif
  108. #ifdef MAX1
  109. int flyexp::DoExport(const TCHAR *name, ExpInterface *ei, Interface *i)                                        // max 1.x
  110. #endif
  111. {
  112.     if (IDOK==DialogBox(hInstance,MAKEINTRESOURCE(IDD_OPTIONS),i->GetMAXHWnd(),(DLGPROC)OptionsProc))
  113.         {
  114.         enum_scene_count e0;
  115.         enum_scene e1;
  116.  
  117.         e0.time=i->GetTime();
  118.         tot_face=0;
  119.         tot_vert=0;
  120.         ei->theScene->EnumTree( &e0 );
  121.  
  122.         if (saveobj)
  123.             _mkdir("objects");
  124.  
  125.         e1.vert=new vector[tot_vert];
  126.         e1.faces=new face[tot_face];
  127.  
  128.         e1.time=i->GetTime();
  129.         ei->theScene->EnumTree( &e1 );
  130.  
  131.         if (savebsp && e1.nfaces)
  132.             {
  133.             e1.compute_scene_normals();
  134.             e1.compute_light();
  135.             e1.build_bsptree();
  136.             e1.nleaf=0;
  137.             e1.enum_leaf(e1.bsp);
  138.             e1.save((char *)name);
  139.             }
  140.  
  141.         delete e1.faces;
  142.         delete e1.vert;
  143.         if (e1.vertcolor)
  144.             delete e1.vertcolor;
  145.         e1.vertcolor=0;
  146.         e1.faces=0;
  147.         e1.vert=0;
  148.         
  149.         }
  150.     
  151.     return 1;
  152. }
  153.  
  154. TCHAR *GetString(int id)
  155.     {
  156.     static TCHAR buf[256];
  157.     if (hInstance)
  158.         return LoadString(hInstance, id, buf, sizeof(buf)) ? buf : NULL;
  159.     return NULL;
  160.     }
  161.  
  162. BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved) 
  163. {
  164.     hInstance = hinstDLL;
  165.  
  166.     if ( !controlsInit ) 
  167.         {
  168.         controlsInit = TRUE;
  169.         
  170.         // jaguar controls
  171. //        InitCustomControls(hInstance);
  172.  
  173.         // initialize Chicago controls
  174.         InitCommonControls();
  175.         }
  176.     switch(fdwReason) 
  177.         {
  178.         case DLL_PROCESS_ATTACH:
  179.             break;
  180.         case DLL_THREAD_ATTACH:
  181.             break;
  182.         case DLL_THREAD_DETACH:
  183.             break;
  184.         case DLL_PROCESS_DETACH:
  185.             break;
  186.         }
  187.     return(TRUE);
  188. }
  189.  
  190.  
  191. //------------------------------------------------------
  192.  
  193. class flyClassDesc:public ClassDesc {
  194.     public:
  195.     int             IsPublic() { return 1; }
  196.     void *            Create(BOOL loading = FALSE) { return new flyexp; }
  197.     const TCHAR *    ClassName() { return GetString(IDS_APPNAME); }
  198.     SClass_ID        SuperClassID() { return SCENE_EXPORT_CLASS_ID; }
  199.     Class_ID        ClassID() { return Class_ID(0x1bbd4eb2, 0x6f94405c); }
  200.     const TCHAR*     Category() { return GetString(IDS_CATEGORY);  }
  201.     };
  202.  
  203. static flyClassDesc desc;
  204.  
  205. __declspec( dllexport ) const TCHAR *
  206. LibDescription() { return GetString(IDS_LONG_DESC); }
  207.  
  208. __declspec( dllexport ) int
  209. LibNumberClasses() { return 1; }
  210.  
  211. __declspec( dllexport ) ClassDesc *
  212. LibClassDesc(int i) {
  213.     switch(i) {
  214.         case 0: return &desc; break;
  215.         default: return 0; break;
  216.         }
  217.     }
  218.  
  219. __declspec( dllexport ) ULONG 
  220. LibVersion() { return VERSION_3DSMAX; }
  221.  
  222. int
  223. flyexp::ExtCount() {
  224.     return 1;
  225.     }
  226.  
  227. const TCHAR *
  228. flyexp::Ext(int n) {    
  229.     switch(n) {
  230.         case 0:
  231.             return _T("bsp");
  232.         }
  233.     return _T("");
  234.     }
  235.  
  236. const TCHAR *
  237. flyexp::LongDesc() {    
  238.     return GetString(IDS_LONG_DESC);
  239.     }
  240.     
  241. const TCHAR *
  242. flyexp::ShortDesc() {    
  243.     return GetString(IDS_SHORT_DESC);
  244.     }
  245.  
  246. const TCHAR *
  247. flyexp::AuthorName() {    
  248.     return GetString(IDS_AUTHOR);
  249.     }
  250.  
  251. const TCHAR *
  252. flyexp::CopyrightMessage() {    
  253.     return GetString(IDS_COPYRIGHT);
  254.     }
  255.  
  256. const TCHAR *
  257. flyexp::OtherMessage1() {        
  258.     return _T("");
  259.     }
  260.  
  261. const TCHAR *
  262. flyexp::OtherMessage2() {        
  263.     return _T("");
  264.     }
  265.  
  266. unsigned int
  267. flyexp::Version() {                
  268.     return 55;
  269.     }
  270.  
  271. void
  272. flyexp::ShowAbout(HWND hWnd) {    
  273.      }
  274.